package com.example.controller;

import com.example.proxy.DefaultProxyBean;
import com.example.service.SysBeanService;
import com.example.service.SysSmsService;
import com.example.service.SysTestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

@RestController
public class SysSmsController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private SysSmsService sysSmsService;

    @Resource
    private SysBeanService sysBeanService;

    @Resource
    private SysTestService sysTestService;

    /***
     * 获取appKey
     */
    @GetMapping(value = "getAppKey")
    public void getAppKey() {
        logger.warn("getAppKey start ========================>>>>");
        logger.warn("smsService.getAppKey(): " + sysSmsService.getAppKey());
        logger.warn("sysTestService.getSmsService().getAppKey(): " + sysTestService.getSmsService().getAppKey());
        logger.warn("getAppKey end ========================>>>>");
    }

    /***
     * 获取AppVal
     */
    @GetMapping(value = "getAppVal")
    public void getAppVal() {
        logger.warn("getAppVal start ========================>>>>");
        logger.warn("smsService.getAppVal(): " + sysSmsService.getAppVal());
        logger.warn("sysTestService.getSmsService().getAppVal(): " + sysTestService.getSmsService().getAppVal());
        logger.warn("getAppVal end ========================>>>>");
    }

    /***
     * 刷新bean属性
     * @param appKey
     * @return
     * @throws Exception
     */
    @GetMapping(value = "refreshBean")
    public String refreshBean(@RequestParam(defaultValue = "sms.appKey") String appKey) throws Exception {
        String uuid = UUID.randomUUID().toString();
        for (DefaultProxyBean refreshProxyBean : sysBeanService.getRefreshProxyBeans()) {
            refreshProxyBean.refreshBeanProp(appKey, uuid);
        }
        return uuid;
    }
}
